/**
 * Copyright (C), 2019-2022
 * FileName: GISUtil
 * Author:   50235
 * Date:     2022-10-27 15:35
 * Description: 坐标工具类
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package cn.lili.common.utils;

import java.util.Collections;
import java.util.List;

/**
 * 〈一句话功能简述〉<br>
 * 〈坐标工具类〉
 *
 * @author mjx
 * @create 2022-10-27
 * @since 1.0.0
 */
public class GISUtil {


    /**
     * 默认地球半径
     */
    private static double EARTH_RADIUS = 6371000;//赤道半径(单位m)

    /**
     * 转化为弧度(rad)
     * */
    private static double rad(double d)
    {
        return d * Math.PI / 180.0;
    }
    /**
     * @param lon1 第一点的精度
     * @param lat1 第一点的纬度
     * @param lon2 第二点的精度
     * @param lat2 第二点的纬度
     * @return 返回的距离，单位m
     * */
    public static double GetDistance(double lat1,double lon1,double lat2, double lon2) {
        double radLat1 = rad(lat1);
        double radLat2 = rad(lat2);
        double a = radLat1 - radLat2;
        double b = rad(lon1) - rad(lon2);
        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
        s = s * EARTH_RADIUS;
        s = Math.round(s * 10000) / 10000;
        return s;
    }


    /**
     * 获取最短的距离
     *
     * @param lat 比较坐标
     * @param lon 比较坐标
     * @param initlat 源坐标
     * @param initlon 源坐标
     * @return
     */
    public  static Double GetShotLocal(Double lat, Double lon, Double initlat, Double initlon) {
        Double x = (initlat - lat) * (initlat - lat);
        Double y = (initlon - lon) * (initlon - lon);
        Double z = Math.sqrt(x + y);
        return z;
    }


    class LocalAddress {

        private Double lat;
        private Double lon;
        private Double distance;

        public LocalAddress() {
            // TODO Auto-generated constructor stub
        }

        public LocalAddress(Double lat, Double lon, Double distance) {
            super();
            this.lat = lat;
            this.lon = lon;
            this.distance = distance;
        }

        public Double getLat() {
            return lat;
        }

        public void setLat(Double lat) {
            this.lat = lat;
        }

        public Double getLon() {
            return lon;
        }

        public void setLon(Double lon) {
            this.lon = lon;
        }

        public Double getDistance() {
            return distance;
        }

        public void setDistance(Double distance) {
            this.distance = distance;
        }

    }
}